import * as actionTypes from './constants'
import {
  getSearchSuggestion,
  getSearchResult
} from '@/services/search-api'
const changeSearchSuggestionAction = searchSuggest => ({
  type: actionTypes.CHANGE_SEARCH_SUGGESTION_RESULT_ACTION,
  searchSuggest
})

export const getSearchSuggestionAction = keywords => {
  return async dispatch => {
    const res = await getSearchSuggestion(keywords)
    dispatch(changeSearchSuggestionAction(res.result))
  }
}
const changeSearchResultAction = searchResult => ({
  type: actionTypes.CHANGE_SEARCH_RESULT_ACTION,
  searchResult
})
export const getSearchResultAction = (keywords, type) => {
  return async dispatch => {
    const res = await getSearchResult(keywords, type)
    dispatch(changeSearchResultAction(res.result))
  }
}